| Conditions | 4 |
| Paths | 170 |
| Total Lines | 155 |
| Code Lines | 105 |
| Lines | 29 |
| Ratio | 18.71 % |
| Changes | 5 | ||
| Bugs | 1 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | /** |
||
| 35 | initDropzone() { |
||
| 36 | if (typeof Dropzone != 'undefined') { |
||
| 37 | //Dropzone.autoDiscover = false; |
||
| 38 | |||
| 39 | // Cards version |
||
| 40 | const dropzoneCards = $('#dropzone-cards'); |
||
| 41 | if(dropzoneCards.length) { |
||
| 42 | |||
| 43 | let dropzoneCardsActionUrl = dropzoneCards.data('action-url'); |
||
| 44 | |||
| 45 | let dropzoneCardsFilePreview = dropzoneCardsElement.find('#dropzone-cards-template'); |
||
|
|
|||
| 46 | dropzoneCardsFilePreview.removeAttr('id'); |
||
| 47 | |||
| 48 | let dropzoneCardsFilePreviewTemplate = dropzoneCardsFilePreview.parent().html(); |
||
| 49 | dropzoneCardsFilePreview.parent().remove(); |
||
| 50 | |||
| 51 | let dropzoneCardForms = $('#dropzone-cards-form').dropzone({ |
||
| 52 | url: dropzoneCardsActionUrl, |
||
| 53 | autoProcessQueue: true, |
||
| 54 | thumbnailWidth: null, |
||
| 55 | thumbnailHeight: null, |
||
| 56 | previewTemplate: dropzoneCardsFilePreviewTemplate |
||
| 57 | }); |
||
| 58 | |||
| 59 | View Code Duplication | dropzoneCards.on("addedfile", function (file) { |
|
| 60 | console.log('titit'); |
||
| 61 | var fileId = 'media' + document.querySelectorAll('.media-list-item').length; |
||
| 62 | file.previewElement.getElementsByTagName('input')[0].setAttribute('id', fileId); |
||
| 63 | file.previewElement.getElementsByTagName('label')[0].setAttribute('for', fileId); |
||
| 64 | |||
| 65 | var imagesFileTypes = ['image/png', 'image/jpg', 'image/jpeg', 'image/gif']; |
||
| 66 | if (imagesFileTypes.indexOf(file.type) != -1) { |
||
| 67 | file.previewElement.querySelector('.media-item-file-details').style.display = 'none'; |
||
| 68 | } else if (file.type === 'application/pdf') { |
||
| 69 | file.previewElement.querySelector('.media-item-file-details').style.display = 'block'; |
||
| 70 | file.previewElement.querySelector('.media-item-icon').innerHTML = '<i class="fas fa-file-pdf"></i>'; |
||
| 71 | } else if (file.type === 'application/doc' | 'application/docx') { |
||
| 72 | file.previewElement.querySelector('.media-item-file-details').style.display = 'block'; |
||
| 73 | file.previewElement.querySelector('.media-item-icon').innerHTML = '<i class="fas fa-file-word"></i>'; |
||
| 74 | } else if (file.type === 'application/ppt' | 'application/pptx') { |
||
| 75 | file.previewElement.querySelector('.media-item-file-details').style.display = 'block'; |
||
| 76 | file.previewElement.querySelector('.media-item-icon').innerHTML = '<i class="fas fa-file-powerpoint"></i>'; |
||
| 77 | } else if (file.type === 'video/mp4' | 'video/webm' | 'video/mkv') { |
||
| 78 | file.previewElement.querySelector('.media-item-file-details').style.display = 'block'; |
||
| 79 | file.previewElement.querySelector('.media-item-icon').innerHTML = '<i class="fas fa-file-video"></i>'; |
||
| 80 | } else if (file.type === 'audio/mpeg') { |
||
| 81 | file.previewElement.querySelector('.media-item-file-details').style.display = 'block'; |
||
| 82 | file.previewElement.querySelector('.media-item-icon').innerHTML = '<i class="fas fa-file-audio"></i>'; |
||
| 83 | } else { |
||
| 84 | file.previewElement.querySelector('.media-item-file-details').style.display = 'block'; |
||
| 85 | file.previewElement.querySelector('.media-item-icon').innerHTML = '<i class="fas fa-file"></i>'; |
||
| 86 | } |
||
| 87 | }); |
||
| 88 | |||
| 89 | dropzoneCards.on("success", function (file, resp) { |
||
| 90 | file.previewElement.querySelector(".media-list-item").classList.remove('uploading'); |
||
| 91 | file.previewElement.querySelector(".upload-progress").style.display = 'none'; |
||
| 92 | file.previewElement.querySelector(".media-item-file-extension").innerHTML = file.type; |
||
| 93 | }); |
||
| 94 | |||
| 95 | dropzoneCards.on("error", function (file) { |
||
| 96 | file.previewElement.querySelector(".media-list-item").classList.remove('uploading'); |
||
| 97 | file.previewElement.querySelector(".upload-progress").style.display = 'none'; |
||
| 98 | file.previewElement.querySelector(".media-item-file-extension").innerHTML = file.type; |
||
| 99 | }); |
||
| 100 | } |
||
| 101 | |||
| 102 | // Table version |
||
| 103 | const dropzoneTable = $('#dropzone-table'); |
||
| 104 | if(dropzoneTable.length) { |
||
| 105 | |||
| 106 | let dropzoneTableActionUrl = dropzoneTable.data('action-url'); |
||
| 107 | |||
| 108 | let dropzoneTableFilePreview = dropzoneTableElement.find('#dropzone-table-template'); |
||
| 109 | dropzoneTableFilePreview.removeAttr('id'); |
||
| 110 | |||
| 111 | let dropzoneTableFilePreviewTemplate = dropzoneTableFilePreview.parent().html(); |
||
| 112 | dropzoneTableFilePreview.parent().remove(); |
||
| 113 | |||
| 114 | let dropzoneTable = $('#dropzone-table-form').dropzone({ |
||
| 115 | url: dropzoneTableActionUrl, |
||
| 116 | autoProcessQueue: false, |
||
| 117 | thumbnailWidth: null, |
||
| 118 | thumbnailHeight: null, |
||
| 119 | previewTemplate: dropzoneTableFilePreviewTemplate, // Define the container to display the previews |
||
| 120 | previewsContainer: ".media-list-table", |
||
| 121 | clickable: "#dropzone-add-file", // Define the element that should be used as click trigger to select files. |
||
| 122 | }); |
||
| 123 | |||
| 124 | dropzoneTable.on("addedfile", function (file) { |
||
| 125 | console.log('test'); |
||
| 126 | var imagesFileTypes = ['image/png', 'image/jpg', 'image/jpeg', 'image/gif']; |
||
| 127 | if (imagesFileTypes.indexOf(file.type) != -1) { |
||
| 128 | file.previewElement.querySelector('.media-item-file-details').style.display = 'none'; |
||
| 129 | } else if (file.type === 'application/pdf') { |
||
| 130 | file.previewElement.querySelector('.media-item-file-details').style.display = 'block'; |
||
| 131 | file.previewElement.querySelector('.media-item-icon').innerHTML = '<i class="fas fa-file-pdf"></i>'; |
||
| 132 | } else if (file.type === 'application/doc' | 'application/docx') { |
||
| 133 | file.previewElement.querySelector('.media-item-file-details').style.display = 'block'; |
||
| 134 | file.previewElement.querySelector('.media-item-icon').innerHTML = '<i class="fas fa-file-word"></i>'; |
||
| 135 | } else if (file.type === 'application/ppt' | 'application/pptx') { |
||
| 136 | file.previewElement.querySelector('.media-item-file-details').style.display = 'block'; |
||
| 137 | file.previewElement.querySelector('.media-item-icon').innerHTML = '<i class="fas fa-file-powerpoint"></i>'; |
||
| 138 | } else if (file.type === 'video/mp4' | 'video/webm' | 'video/mkv') { |
||
| 139 | file.previewElement.querySelector('.media-item-file-details').style.display = 'block'; |
||
| 140 | file.previewElement.querySelector('.media-item-icon').innerHTML = '<i class="fas fa-file-video"></i>'; |
||
| 141 | } else if (file.type === 'audio/mpeg') { |
||
| 142 | file.previewElement.querySelector('.media-item-file-details').style.display = 'block'; |
||
| 143 | file.previewElement.querySelector('.media-item-icon').innerHTML = '<i class="fas fa-file-audio"></i>'; |
||
| 144 | } else { |
||
| 145 | file.previewElement.querySelector('.media-item-file-details').style.display = 'block'; |
||
| 146 | file.previewElement.querySelector('.media-item-icon').innerHTML = '<i class="fas fa-file"></i>'; |
||
| 147 | } |
||
| 148 | // Hookup the start button |
||
| 149 | file.previewElement.querySelector(".start").onclick = function() { dropzoneTable.enqueueFile(file); }; |
||
| 150 | }); |
||
| 151 | |||
| 152 | dropzoneTable.on("totaluploadprogress", function(progress) { |
||
| 153 | document.querySelector("#dropzone-table-total-progress .progress-bar").style.width = progress + "%"; |
||
| 154 | }); |
||
| 155 | |||
| 156 | dropzoneTable.on("sending", function(file) { |
||
| 157 | // Show the total progress bar when upload starts |
||
| 158 | document.querySelector("#dropzone-table-total-progress").style.opacity = "1"; |
||
| 159 | // And disable the start button |
||
| 160 | file.previewElement.querySelector(".start").setAttribute("disabled", "disabled"); |
||
| 161 | }); |
||
| 162 | |||
| 163 | dropzoneTable.on("success", function (file, resp) { |
||
| 164 | file.previewElement.querySelector(".upload-progress").style.display = 'none'; |
||
| 165 | file.previewElement.querySelector(".media-item-file-extension").innerHTML = file.type; |
||
| 166 | }); |
||
| 167 | |||
| 168 | dropzoneTable.on("error", function (file) { |
||
| 169 | file.previewElement.querySelector(".upload-progress").style.display = 'none'; |
||
| 170 | file.previewElement.querySelector(".media-item-file-extension").innerHTML = file.type; |
||
| 171 | }); |
||
| 172 | |||
| 173 | dropzoneTable.on("queuecomplete", function(progress) { |
||
| 174 | document.querySelector("#dropzone-table-total-progress").style.opacity = "0"; |
||
| 175 | }); |
||
| 176 | |||
| 177 | // Setup the buttons for all transfers |
||
| 178 | // The "add files" button doesn't need to be setup because the config |
||
| 179 | // `clickable` has already been specified. |
||
| 180 | document.querySelector("#dropzone-table-actions .start").onclick = function() { |
||
| 181 | dropzoneTable.enqueueFiles(dropzoneTable.getFilesWithStatus(Dropzone.ADDED)); |
||
| 182 | }; |
||
| 183 | |||
| 184 | document.querySelector("#dropzone-table-actions .cancel").onclick = function() { |
||
| 185 | dropzoneTable.removeAllFiles(true); |
||
| 186 | }; |
||
| 187 | } |
||
| 188 | } |
||
| 189 | } |
||
| 190 | |||
| 194 | } |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.